// 导入API
import request from '@/utils/request'

// 初始状态
const state = {
  wishCategories: [], // 愿望分类列表
  todoCategories: [], // 待办分类列表
  achievementCategories: [], // 成果分类列表
  loading: false
}

// getter
const getters = {
  wishCategories: state => state.wishCategories,
  todoCategories: state => state.todoCategories,
  achievementCategories: state => state.achievementCategories,
  loading: state => state.loading
}

// mutations
const mutations = {
  SET_WISH_CATEGORIES(state, categories) {
    state.wishCategories = categories
  },
  SET_TODO_CATEGORIES(state, categories) {
    state.todoCategories = categories
  },
  SET_ACHIEVEMENT_CATEGORIES(state, categories) {
    state.achievementCategories = categories
  },
  SET_LOADING(state, loading) {
    state.loading = loading
  }
}

// actions
const actions = {
  // 获取分类列表
  async getCategoryList({ commit }, type) {
    commit('SET_LOADING', true)
    
    try {
      // 这里应该调用分类API，暂时使用模拟数据
      let categories = []
      
      if (type === 1) { // 待办分类
        categories = [
          { id: 1, name: '工作', icon: 'work' },
          { id: 2, name: '学习', icon: 'study' },
          { id: 3, name: '生活', icon: 'life' },
          { id: 4, name: '其他', icon: 'other' }
        ]
        commit('SET_TODO_CATEGORIES', categories)
      } else if (type === 2) { // 愿望分类
        categories = [
          { id: 1, name: '学习', icon: 'study' },
          { id: 2, name: '旅行', icon: 'travel' },
          { id: 3, name: '健康', icon: 'health' },
          { id: 4, name: '事业', icon: 'career' }
        ]
        commit('SET_WISH_CATEGORIES', categories)
      } else if (type === 3) { // 成果分类
        categories = [
          { id: 1, name: '学习', icon: 'study' },
          { id: 2, name: '工作', icon: 'work' },
          { id: 3, name: '技能', icon: 'skill' },
          { id: 4, name: '生活', icon: 'life' }
        ]
        commit('SET_ACHIEVEMENT_CATEGORIES', categories)
      }
      
      return categories
    } catch (error) {
      console.error('获取分类列表失败', error)
      throw error
    } finally {
      commit('SET_LOADING', false)
    }
  }
}

export default {
  namespaced: true,
  state,
  getters,
  mutations,
  actions
} 